package com.demo.index.controller;

import com.demo.component.bean.AsyncTask;
import com.demo.component.bean.Properties;
import com.demo.component.bean.RedisUtils;
import com.demo.component.runnable.TestRunnable;
import com.demo.index.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/")
public class IndexController {

    @Autowired
    private Properties properties;
//    @Autowired
//    private CustomSource source;
    @Autowired
    private AsyncTask asyncTask;

    @Autowired
    private TestService testService;

    @Autowired
    private RedisUtils redisUtils;

	@RequestMapping("")
    public String toIndex(){
        return "index/index";
    }

    @RequestMapping("/config")
    @ResponseBody
    public String config(){
        return properties.getName();
    }

    @RequestMapping("/test")
    @ResponseBody
    public String test(){
//        try {
//            // 异步线程
//            asyncTask.execute(new TestRunnable("output Web", source));
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return testService.test();
    }

    @RequestMapping("/set-redis")
    @ResponseBody
    public String setRedis() {
	    redisUtils.set("springcloud_test", 1000, "1");
	    return "success";
    }

    @RequestMapping("/get-redis")
    @ResponseBody
    public String getRedis() {
        return redisUtils.get("springcloud_test");
    }
}
